/**
 * 
 */
package com.doone.telmarket.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.doone.telmarket.domain.Comment;
import com.doone.telmarket.infrastructure.dao.CommentDAO;
import com.doone.telmarket.vo.CommentView;

/**
 * @author 吴同庆
 * @date 2009-10-14
 * @description
 * @package com.doone.telmarket.service
 */
@Service("commentService")
public class CommentServiceImpl implements CommentService {
	
	private static final String UPDATE_COMMENT_ERROR = "审核评论更新出错:";
	
	@Autowired
	private CommentDAO commentDAO;
	
	public Comment publishComment(Comment comment) {
		Integer key = commentDAO.insertComment(comment);
		comment.setCommentId(key);
		return comment;
	}

	public Comment verifyComment(Integer commentId, String verifyState) {
		Comment comment = commentDAO.selectCommentByPrimaryKey(commentId);
		comment.verifyComment(verifyState);
		int count = commentDAO.updateCommentByVerifyStateAndTime(comment);
		if(count != 1)
			throw new RuntimeException(UPDATE_COMMENT_ERROR+commentId);
		return comment;
	}

	public List<Comment> viewComments(CommentView commentView) {
		
		return commentDAO.selectCommentByServiceCode(commentView);
	}

}
